class Solution {
public:
    int dist(int a, int b)
    {
        int x = abs(a - b);
        int y = abs(26 - a + b);
        //0 - 25
        return min(x, y);

    }
    string getSmallestString(string s, int k)
    {
        int n = s.size();
        for (int i = 0; i < n && k; i++)
        {
            if (s[i] == 'a') continue;
            for (int j = 0; j < 26; j++)
            {
                int dis = dist(s[i] - 'a', j);
                if (dis <= k)
                {
                    s[i] = j + 'a';
                    k -= dis;
                    break;
                }
            }
        }
        return s;
    }
};